/*@ File Name : list.h
  @ Date : 18/11/2011
  @ Author : Guillaume Collombet, Ulysse Mensa, Sylvain Chambe

Fireworks simulation projet
Copyright (C) 2011 Guillaume Collombet, Ulysse Mensa, Sylvain Chambe

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

You can contact us by sending mail at fireworks-simulation-project@googlecode.com*/

#if !defined(_LIST_H)
#define _LIST_H

#include "const.h"
#include "type.h"

typedef Type32 Element;

struct s_Cell
{
  Element value;
  struct s_Cell* next;
} typedef  Cell;

struct s_List
{
  Cell *first;
  Cell *last;
  int count;
} typedef List;

typedef struct s_List Stack;
typedef struct s_List Queue;

#define Queue_Enqueue(l,e) List_InsertLast(l,e)
#define Queue_Dequeue(l) List_ReadFirst(l)
#define Queue_Init(l) List_Init(l)
#define Queue_Destroy(l) List_Destroy(l)
#define Queue_IsEmpty(l) List_IsEmpty(l)
#define Queue_Copy(source,destination) List_Copy(source,destination)

#define Stack_Push(l,e) List_InsertLast(l,e)
#define Stack_Pop(l) List_ReadLast(l)
#define Stack_Init(l) List_Init(l)
#define Stack_Destroy(l) List_Destroy(l)
#define Stack_IsEmpty(l) List_IsEmpty(l)
#define Stack_Copy(source,destination) List_Copy(source,destination)

void List_Init(List * l);
void List_Copy(const List * source,List** destination);
int List_IsEmpty(const List * l);
Cell* List_InsertAt(List* l, Element e, int position);
Cell* List_Insert(List* l, Element e, Element at);
void List_InsertFirst(List* l,Element e);
void List_InsertLast(List* l,Element  e);
void List_Remove(List* l, Element e);
Element List_GetFirst(const List* l);
Element List_GetLast(const List* l);
Element List_ReadFirst(List* l);
Element List_ReadLast(List* l);
Cell* List_Search(const List* l,Element e);
void List_ToArray(Element** element,const List* l);
void List_Destroy(List* l);

#endif /*_LIST_H*/